There is DllMain function that calls DeleteThreadxxxData if OpenCV is build as dll.

BOOL WINAPI DllMain( HINSTANCE, DWORD  fdwReason, LPVOID )
{
    if( fdwReason == DLL_THREAD_DETACH || fdwReason == DLL_PROCESS_DETACH )
    {
        cv::deleteThreadAllocData();
        cv::deleteThreadRNGData();
    }
    return TRUE;
}

In case of static build TlsFree is called inside TlsSlot methods.