Nice theory, but there are some major problems with it. Among other things, since defendants generally do not have the same discovery requirements as prosecutors, defendants may decide to withhold certain exculpatory evidence until trial. A prosecutor may have a case that is absolutely rock-solid according to all the information he has access to, and yet have it undermined by evidence he couldn't have known anything about.
At present, defendants generally have an incentive to let reasonable prosecutors know of such evidence in the hopes that the prosecutor will save everyone's time and drop the case. If defendants could be assured that their costs would be reimbursed regardless they might feel less incentive, especially since holding back could slightly increase their chances for acquittal.
I really don't see any way of avoiding moral hazards in this sort of loser-pays scenario. I also think there needs to be separation of the issues of whether (1) the defendant deserves some reimbursement, or (2) the prosecutor deserves to be penalized personally. I would suggest that setting up clear standards to allow a prosecutor to be personally sued for a defendant's legal costs in the event that the defendant can prove that no reasonable prosecutor could have believed beyond a reasonable doubt that the defendant was guilty of the specific named offense(s) and that he could prove it.