Why is Target Display Mode via Thunderbolt so unreliable for me?
If you can touch the cable and have it drop in and out, I would say you either have a bad cable or bad connector (or both?) on one of the computers.

Try your setup with a different cable and see if you get the same result.

Good luck!