Just put this code on your .htaccess file:
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://([^.]+\.)?example\.com [NC]
RewriteRule \.(gif|jpe?g?|png)$ - [NC,F,L]
</IfModule>
Where example.com should match your domain.