calc returns a reference to a temporary object you get from i*i. The problem is that this temporary object will only exist on that line. It will not exist outside the function. So what calc actually returns is a reference to some non existing object.
There is no reason to return a reference here. Just return a normal double.
At this line here return i*i;
a value is calculated - i*i. That value exists somewhere in memory. When you return a reference (which is what you're doing with that &) what gets returned is not a copy of that value - it is that actual value, at that place in memory.
However, when a function finishes, anything you made inside that function (apart from anything you made using new, but that's not relevant here) is destroyed. All the memory that was used by that function is tidied up and made available for something else to use. So what happened to the value you returned? It no longer exists. This is a big problem if you try to use it - using values that don't exist any more is not a good idea.