Thanks for your query.Based on the facts that you have posted it appears that you have developed infection of the Testicle termed as Orchitis.It is mostly a bacterial infection and not due to masturbation
This can be confirmed by ultrasound
scanning of the scrotum.
Take some antibiotics like Augmentin
twice daily along with some anti inflammatory medication like Diclofenac
. Get prescription of these drugs from your family Physician,It should get resolved in a week.