An Orange County sheriff's deputy stands in the doorway after loading prisoners in to jail in Fullerton, California, June 23, 2009. REUTERS/Lucy Nicholson

SAN FRANCISCO (Reuters) - U.S. judges on Tuesday told California to prepare to release more than 40,000 of its 150,000 inmates to reduce overcrowding in state prisons, which suffer from massive healthcare problems.

The cash-strapped state already plans to release ailing and short-term inmates for budget issues. That would clear up to 37,000 beds over two years, estimated California Department of Corrections and Rehabilitation Secretary Matthew Cate.

But he said an order from federal judges would set a “dangerous precedent” and argued at a news conference that California had cleaned up prisons and hired medical professionals to fill chronic gaps that had left prisoners without adequate physical or mental care.

The federal three-judge panel in February made a tentative ruling pointing toward release. On Tuesday the judges ordered the state in 45 days to prepare a plan to cut overcrowding to 137.5 percent of capacity.

That would amount to a cut of 40,591 inmates in its 33 prisons, it said. But officials intend to appeal a release order, which would follow Tuesday’s order for a plan.