What a mess!
Two possibilities here:
1. The referee changed his mind (for whatever reason), therefore the cards resulting in the dismissals never actually happened. In this case, although it doesn't look good, the result should stand as the referee has technically been correct in Law.
2. The...