In this situation, "the" is also possible, in which case you would be talking about the very specific reference he gave you. The sense of "a reference" on the second occasion is still that the reference he gave you is an example, an instance of all references. The student was grateful for the fact that the professor gave any reference - the precise reference did not matter at the time of thanking.
New words, one handy idiom, and a 2-minute quiz — delivered to your inbox to keep your streak alive.
zbigI'd like to thank you for giving me a reference.I am thanking him for his act of kindness and consideration, not for the particular email or piece of paper.
zbigI'd like to thank you for giving me a reference.When you need something or ask for something (countable), you ask for "a ...". When you receive it, it's still "a ...".
zbigI am assuming that in this context, the student could also say: "thank you for the reference", if both the professor and the student understand which one is referred to, right?Yup!