Answer can be found here: https://stackoverflow.com/questions/13863087/wordpress-custom-widget-image-upload
Even though the problem described isn’t exactly the same as I had, the code posted in the answer still helped me as that code actually does exactly what I needed.
I also think that I didn’t originally find this answer as it’s on the regular Stack Overflow and not the WordPress part of it.