Would a pupil say: "I'm afraid of getting bad marks." or "I'm afraid to get bad marks."? What is the nuance introduced by OF and TO?
There is another way to differentiate.
Afraid Of + ing is used when you generically or generally fear that thing. Well, afraid + to INF is used when you fear what would happen for this particular time.
You’re not usually afraid of speaking in public, so don’t be afraid to speak this time.
In your example, "I'm afraid of getting bad marks," means generally you fear to get bad marks, while "I'm afraid to get bad marks," means you fear to get bad marks from the coming exams.