All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
If the semen is not ejaculated from that masturbation, your fasting is valid; otherwise, it is invalid and you have to make up for it. However, if you were ignorant of the ruling that fasting is nullified by this act, our Fatwa is that you are not obliged to make up for the fasting of that day, because many people - those who have no knowledge of Fiqh - may be unaware of the Sharee'ah ruling that fasting is nullified by masturbation. Yet, to be on the safe side, making up for those days is preferred. So, if you choose to make up for those days, you are not obliged to fast them consecutively; rather you are allowed to fast them separately.
Allah knows best.