Invalid Python expression when using driver with Python script
Found a solution after a while. Seems like global functions doesn't work the same way in Blender as in raw Python.

I used mini3d's solution found on the blender forum: https://www.blender.org/forum/viewtopic.php?t=27291

Here's a summary of the solution

import bpy

# Define global variables
bpy.types.Scene.prevTime = bpy.props.FloatProperty()

def getSettings():
    settings = bpy.data.scenes.get("Settings")
    if settings is None:
        settings = bpy.data.scenes.new("Settings")

    return settings

def rotate(rotSpeed, curRot):
    .
    .
    getSettings().prevTime = time
    .
    .


EDIT: Global variables do in fact work the same way. The following solution is much cleaner as suggested by batFINGER

The problem was that I tried to edit a global variable in a function without using the keyword "global".

import bpy

# Define global variables
prevTime = 0

def rotate(rotSpeed, curRot):
    # This will give us the ability to edit the global variable
    global prevTime  
    .
    .