The algorithm is relatively simple - you need the id where the points supplied is greater than or equal to the level
:
SELECT id
FROM points_level
WHERE
(<points_input> >= level)
-- For negative input, return the lowest level
OR (<points_input> < 0 AND level <= 0)
ORDER BY level DESC LIMIT 1
http://sqlfiddle.com/#!2/07601/4
Review the MySQL CREATE FUNCTION
syntax for the proper way to wrap it in a function (if you feel you really need that).
CREATE FUNCTION calc_level (in_points INT)
RETURNS INT
BEGIN
DECLARE id_out INT;
SET id_out = (
SELECT id
FROM points_level
WHERE
in_points >= level
OR (in_points < 0 AND level <= 0)
ORDER BY level DESC LIMIT 1
);
RETURN id_out;
END