I wouldn't touch the deal with the 11' pole that I use to avoid touching things with a 10' pole.
No matter what the contract says, if you give the money to the former roommate someday you will move out and good luck getting money from your replacement.
If the contract is with the owner of the dwelling, then your deposit goes to the owner.
If the contract is with the two (or one) roommates than your deposit goes to them and they will be obligated to return it to you when you move out. What they do with the money (give it to the departing roommate) won't absolve them from that obligation.
However, with roommate situations where roommates come and go I suspect the day will come when it's time to get your deposit back and everybody will be pointing fingers at everybody else and you'll never see your money.
My advice: Avoid living with roommates. Find yourself a cheap efficiency if that's all you can afford. Otherwise, you'll be back here one day sobbing "What are my rights?"

