As far as I know, there is nothing in the Bible that discusses what you should think about when you masturbate. I checked the Skeptic’s Annotated Bible for a discussion of masturbation. It points to Genesis 38:7 to 38:10. A person is told that he must marry his brother’s wife, because a man is required to marry his dead brother’s wife if she has not had any children. (Deuteronomy 25:5 to 25:10). The guy is not too keen on this idea, so he masturbates instead of having sex. God kills him for this. Some interpret the passage as saying that masturbation is wrong.
38:7 And Er, Judah’s firstborn, was wicked in the sight of the LORD; and the LORD slew him.
38:8 And Judah said unto Onan, Go in unto thy brother’s wife, and marry her, and raise up seed to thy brother.
38:9 And Onan knew that the seed should not be his; and it came to pass, when he went in unto his brother’s wife, that he spilled it on the ground, lest that he should give seed to his brother.
38:10 And the thing which he did displeased the LORD: wherefore he slew him also.