Are you certain $row[0] contains a valid userid? Use die($row[0]); to check.
Don't quote the integer value.
Are you sure $db is in scope?
What hook are you doing this on?
Code:
$userid = (int) $row[0];
die($userid); // use this for a sanity check...
$db->query_read("
SELECT filename
FROM " . TABLE_PREFIX . "customprofilepic
WHERE userid = $userid
");