You can do it if you setup your material id colors correctly. You can use the rgb channels of the colors and combinations of them to set different material IDs. Then you can take the material id color in nuke and process it thru some simple boolean arithmetic tools and you'll get black and white matte of the given material. This is one way to do it:
CODE
Mat# red green blue booleans equation
01 0 0 0 (inv red) min (inv blue) min (inv green)
02 0 0 255 (inv red) min (inv blue) min green
03 0 255 0 (inv red) min blue min (inv green)
04 0 255 255 (inv red) min blue min green
05 255 0 0 red min (inv blue) min (inv green)
06 255 0 255 red min (inv blue) min green
07 255 255 0 red min blue min (inv green)
08 255 255 255 red min blue min green
So for example you need to set up a material id for material number 07. You setup its color to RGB (255, 255, 0) and render it. Then to get a matte our of it you invert the GREEN channel and do a MIN operation between the result of the invert and the RED and the BLUE channel and you'll get white only in the areas where your material id was set as RGB (255, 255, 0).
Hope it makes sense.