What to do if a professor confused me with another student in a letter of reference?
I am flabbergasted that the Professor here would not take the initiative to correct his own mistake.  Writing a letter of recommendation for the wrong student ---and making negative remarks that do not apply, that cost the student a graduate position--- is a huge stuff-up.  Any decent marginally-competent person would be mortified at making this mistake and would immediately take action to correct it, without having to be asked.  (It might be too late for the admissions process that occurred, but the least the Professor could do is to write to the affected universities and correct the record, so that it doesn't negatively affect you in future applications.)  It is good that he told you about the error, but that is really insufficient without him taking some further action to correct the error.

If this Professor has not already taken it upon himself to correct his error by writing back to those universities, to at least correct the record, then he is a total deadbeat.  You should consider putting in a formal complaint to your university.  This could also be legally actionable as negligence, breach of contract, defamation, etc., and it reflects terribly on the university that the student would be the one to have to take the initiative here.

If you are more forbearing than me then you should take Strongbad's excellent and sensible advice of approaching the matter gently, to get a good reference for next time.  However, if you are as pissed-off about this situation as I am reading about it, and you decide you want to go full scorched-Earth, here is an alternative course of action:  Speak to a lawyer and get him to write a letter to the university putting them on notice that their negligence/defamation has caused actionable damage to you, and that you expect them to take action to "mitigate that damage".  (They will know what this means.)  Make an appointment with a senior administrator at the university (e.g., their legal counsel, vice-chancellor's office, etc.), and turn up with a senior support-person (e.g., a lawyer, or if this is too expensive, at least a middle-aged person who knows how to handle these situations).  Reiterate that the university has been negligent and has defamed you to other institutions, and this has caused actionable damage to you.  Ask them for suggestions of how they intend to go about mitigating the damage to you, and make sure these are accompanied by guarantees.  Advise them that if the damage to you is not mitigated by a successful application in the next round of grad-school entry, you will be left with no choice but to make a formal complaint to the relevant university Ombudsman and take legal action to recover damages.