By the law of Moses, such images are a temptation to the venial sin of spilling your seed.
The proscribed penance is to admit you are unclean and to walk around the perimeter of the camp of the faithful until nightfall. Then you are clean once again.
Unlike adultery, it is not a mortal sin.
To avoid such temptation, one should get married and produce lots of children, provide for their families and raise them in the faith.