Correctly remove the reference type when copying the thread function into the thread data area so we don't end up with a dangling reference