MPs approve legislation to release thousands of prisoners who have served 40% of sentence