changing this code to check for a collision from a specific layer
Yes, checkLayers() is what is performs the collision test, and compares every layer in the Comp against the one running the script.

To check against only one layer, you could re-write that function a little cleaner, but here's a quick solution.

First, remove the lines that start and end the for loop, since you'll only be checking one layer. But don't remove the code inside the for loop, since that code is what does the collision check. 

for ( idx = 1; idx &lt;= thisComp.numLayers; idx++){  // delete
    ... // keep this stuff
} // delete


You can also delete these two lines, since you don't need to check every layer in the Comp for whether it's the same as the layer running the script, or whether the layer is active or not:

if (index == idx) continue; // skips if the comparison layer is the same as the current layer


if (! L.active) continue;   // skips if the comparison layer is inactive


Last, modify this line:

L = thisComp.layer(idx);


… to make L the one layer that you want to compare to. You might do that by referencing a layer by index or name, such as:

L = thisComp.layer("Name of Single Layer to Compare");


Check the Adobe documentation on Comp attributes and methods to see other options for referencing a specific layer.

You do need the if (checkLayers()) 1 else 0 line at the end, because that's the “switch” that returns the final value of your expression, depending on whether there was a collision (returns 1) or not (returns 0).