The story
The loss of a testicle would be a high price to pay for something. This synonym of give one's eye-teeth and give one's right arm most likely came after those, having been modeled after them facetiously.
Etymology from Wiktionary, CC BY-SA 4.0.