LIMA, Peru (AP) — A high court in Peru ruled Thursday that former President Ollanta Humala and his wife must be freed from prison while prosecutors investigate their alleged involvement in multimillion-dollar kickback schemes.

Humala and Nadine Heredia were sent to separate prisons last summer as prosecutors investigated them for allegedly taking money from Odebrecht, the Brazil-based multinational construction company that has admitted to bribing dozens of politicians in Latin America.

But with prosecutors still not pressing formal charges against the couple, Peru's Constitutional Court ruled that their arrest and imprisonment failed to comply with due process laws.

The ruling comes on the heels of the resignation of President Pedro Pablo Kuczynski, who stepped down last month after a group of opposition congressmen published documents that showed one of his companies had done consulting work for Odebrecht.

Former President Alejandro Toledo is also wanted by Peruvian prosecutors for allegedly taking $20 million in bribes from the Brazilian company in exchange for a highway contract. Toledo claims he is innocent and is currently at large in the United States, where he has argued that the investigations of him are politically motivated.

The corruption scandals have upended Peruvian politics and led to calls for swift action against the country's political elite.

But on Thursday, Peru's high court encouraged prosecutors to be more careful in how they proceed with graft cases.

"We need to make sure our fight against corruption is legal, so that it does not lose legitimacy," said the court's president, Ernesto Blume.

Copyright 2018 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.