I declared a variable outside the function like this:
var s: Int = 0
passed it such as this:
def function(s: Int):
If you just want to increment a variable starting with 3
val nextId = { var i = 3; () => { i += 1; i } }
then invoke it:
nextId()