The episode is based on a body swap scenario in which no pair of bodies can swap minds more than once. The proof demonstrates that after any sequence of mind switches, each mind can be returned to its original body by using two additional individuals who have not yet swapped minds with anyone.
I know there are other instances of this scenario occurring in books and TV. I recall the episode of Stargate SG-1 ("Holiday", S2:E17) where they body swap after visiting a planet and meeting Ma'chello, but had to figure out that they could not swap back directly with a previously switched pair.
Futurama was blessed with writers with advanced degrees, and I think their approach to making science and mathematics based jokes was about perfect. In the situations where they're doing something that breaks a law of reality, they have some fun little explanation of how that's possible ("Scientists increased the speed of light..").
I think this is one of the raisins that I appreciate the show on a level all its own.